package com.housekeeping.housekeeping.serviceTest.service.impl;/*
 * @author  pyh
 * @date  2021/1/22 0022 下午 3:38
 * @version 1.0
 * @since JDK1.8_241
 */

import com.housekeeping.housekeeping.order.entity.Order;
import com.housekeeping.housekeeping.order.utils.PageUtils;
import com.housekeeping.housekeeping.serviceTest.dao.impl.OrderTestDaoImpl;
import com.housekeeping.housekeeping.serviceTest.entity.Orders;
import com.housekeeping.housekeeping.serviceTest.service.SearchTestService;

import java.sql.SQLException;
import java.util.List;

public class SearchTestServiceImpl implements SearchTestService {
    private OrderTestDaoImpl orderTestDao = new OrderTestDaoImpl();
    @Override
    public PageUtils<List<Orders>> getStateList(int status, int page, int size) throws SQLException {
        PageUtils<List<Orders>> pageObj = new PageUtils<>();
        List<Orders> stateList = orderTestDao.getStatusList(status, (page - 1) * size, size);
        int stateCount = orderTestDao.getStatusCount(status);

        pageObj.setData(stateList);
        //设置总条数（用于返回前端进行分页效果）
        pageObj.setTotalCount(stateCount);
        //设置当前页为当前请求页
        pageObj.setCurrentPage(page);
        return pageObj;
    }

    @Override
    public PageUtils<List<Orders>> getPAndSList(String phone, int status, int page, int size) throws SQLException {
        PageUtils<List<Orders>> pageObj = new PageUtils<>();
        List<Orders> phoneList = orderTestDao.getPhonesList(phone, status, (page - 1) * size, size);
        int stateAndPhoneCount = orderTestDao.getStatusAndPhoneCount(status, phone);

        pageObj.setData(phoneList);
        //设置总条数（用于返回前端进行分页效果）
        pageObj.setTotalCount(stateAndPhoneCount);
        //设置当前页为当前请求页
        pageObj.setCurrentPage(page);
        return pageObj;
    }
}
